package com.ivanjava.spbdemo1.controller;

import com.ivanjava.spbdemo1.pojo.ResponseMessage;
import com.ivanjava.spbdemo1.pojo.User;
import com.ivanjava.spbdemo1.pojo.dto.UserDTO;
import com.ivanjava.spbdemo1.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController // 接口可以返回对象转换的 json数据
@RequestMapping("/user") // 接口路径映射
public class UserController {

    @Autowired
    IUserService userService;

    // REST风格的接口：GET查, POST增, PUT改, DELETE删
    // 增
    @PostMapping
    public ResponseMessage<User> add(@RequestBody @Validated UserDTO user) {
        User userNew = userService.add(user);
        return ResponseMessage.success(userNew);
    }

    // 删
    //@DeleteMapping
    // 改
    //@PutMapping
    // 查
    //@GetMapping
}
